using System;
using System.Collections.Specialized;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MetaBuilders.Irc;
using MetaBuilders.Irc.Messages;

namespace MetaBuilders.NeboTests
{

	[TestClass]
	public class MonitorTests : MessageTester
	{

		[TestMethod]
		public void Monitor730Test()
		{
			String[] raws = new String[] {
				":irc.example.com 730 artificer artificer!artificer@comcast.net,nebobot!nebobot@example.com"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( MonitoredUserOnlineMessage ) );
			}

			MonitoredUserOnlineMessage msg;

			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as MonitoredUserOnlineMessage;
			Assert.AreEqual( 2, msg.Users.Count );
			Assert.AreEqual( "artificer", msg.Users[ 0 ].Nick );
			Assert.AreEqual( "nebobot", msg.Users[ 1 ].Nick );
		}

		[TestMethod]
		public void Monitor731Test()
		{
			String[] raws = new String[] {
				":irc.example.com 731 artificer nebobot,chanserv"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( MonitoredUserOfflineMessage ) );
			}

			MonitoredUserOfflineMessage msg;

			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as MonitoredUserOfflineMessage;
			Assert.AreEqual( 2, msg.Nicks.Count );
			Assert.AreEqual( "nebobot", msg.Nicks[ 0 ] );
			Assert.AreEqual( "chanserv", msg.Nicks[ 1 ] );
		}

		[TestMethod]
		public void Monitor732Test()
		{
			String[] raws = new String[] {
				":irc.example.com 732 artificer nebobot,chanserv"
			};

			foreach( String raw in raws ) {
				AssertRoundTripAndType( raw, typeof( MonitorListReplyMessage ) );
			}

			MonitorListReplyMessage msg;

			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as MonitorListReplyMessage;
			Assert.AreEqual( 2, msg.Nicks.Count );
			Assert.AreEqual( "nebobot", msg.Nicks[ 0 ] );
			Assert.AreEqual( "chanserv", msg.Nicks[ 1 ] );
		}

		[TestMethod]
		public void Monitor733Test()
		{
			String[] raws = new String[] {
				":irc.example.com 733 artificer :End of MONITOR list"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( MonitorListEndReplyMessage ) );
			}

		}

		[TestMethod]
		public void Monitor734Test()
		{
			String[] raws = new String[] {
				":irc.example.com 734 artificer 100 nebobot,chanserv :Monitor list is full."
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( MonitorListFullMessage ) );
			}

			MonitorListFullMessage msg;

			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as MonitorListFullMessage;
			Assert.AreEqual( 2, msg.Nicks.Count );
			Assert.AreEqual( "nebobot", msg.Nicks[ 0 ] );
			Assert.AreEqual( "chanserv", msg.Nicks[ 1 ] );
			Assert.AreEqual( 100, msg.Limit );
		}

		[TestMethod]
		public void MonitorClearTest()
		{
			String raw = ":hotspeed.sg.as.dal.net MONITOR C";

			AssertRoundTripAndType( raw, typeof( MonitorListClearMessage ) );
		}

		[TestMethod]
		public void WatchStatsTest()
		{
			String raw = ":hotspeed.sg.as.dal.net MONITOR S";

			AssertRoundTripAndType( raw, typeof( MonitorStatusRequestMessage ) );
		}

		[TestMethod]
		public void WatchListTest()
		{
			String[] raws = new String[] {
				":hotspeed.sg.as.dal.net MONITOR L"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( MonitorListRequestMessage ) );
			}
		}

		[TestMethod]
		public void MonitorAddTest()
		{
			String[] raws = new String[] {
				":hotspeed.sg.as.dal.net MONITOR + artificer,foo"
				,":hotspeed.sg.as.dal.net MONITOR + ImNotHere"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( MonitorAddUsersMessage ) );
			}

			MonitorAddUsersMessage msg;

			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as MonitorAddUsersMessage;
			Assert.AreEqual( 2, msg.Nicks.Count );
			Assert.AreEqual( "artificer", msg.Nicks[ 0 ] );
			Assert.AreEqual( "foo", msg.Nicks[ 1 ] );

			msg = MessageParserService.Service.Parse( raws[ 1 ] ) as MonitorAddUsersMessage;
			Assert.AreEqual( 1, msg.Nicks.Count );
			Assert.AreEqual( "ImNotHere", msg.Nicks[ 0 ] );

		}

		[TestMethod]
		public void MonitorRemoveTest()
		{
			String[] raws = new String[] {
				":hotspeed.sg.as.dal.net MONITOR - artificer"
			};

			foreach ( string raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( MonitorRemoveUsersMessage ) );
			}
			MonitorRemoveUsersMessage msg;
			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as MonitorRemoveUsersMessage;
			Assert.AreEqual( 1, msg.Nicks.Count );
			Assert.AreEqual( "artificer", msg.Nicks[ 0 ] );
		}
	}
}
